<cfquery name = "qcheck" datasource="#request.dsn#" maxrows="1">
SELECT * FROM blog_posts
WHERE b_id = <cfqueryparam value="#url.b_id#" cfsqltype="cf_sql_integer"> 
</cfquery>

<cfif qcheck.recordcount GT 0>
	<cfif fileexists('#request.basepath#blog/#qcheck.b_year#/#qcheck.b_month#/#qccheck.b_day#/#qcheck.b_file#')>
		<cffile action="delete" file="#request.basepath#blog/#qcheck.b_year#/#qcheck.b_month#/#qccheck.b_day#/#qcheck.b_file#">
	</cfif>
    <!---remove the directory if it's empty--->
    <cfif directoryexists('#request.basepath#blog/#qcheck.b_year#/#qcheck.b_month#/#qcheck.b_day#/')>
        <cfdirectory action="list" directory="#request.basepath#blog/#qcheck.b_year#/#qcheck.b_month#/#qcheck.b_day#/" name="qfolder">
        <cfif qfolder.recordcount IS 0>
            <cfdirectory action="delete" directory="#request.basepath#blog/#qcheck.b_year#/#qcheck.b_month#/#qcheck.b_day#/">		
        </cfif>
    </cfif>
    <cfquery name = "qdeleterec" datasource="#request.dsn#">
    DELETE FROM blog_posts
    WHERE b_id = <cfqueryparam value="#url.b_id#" cfsqltype="cf_sql_integer"> 
    </cfquery>
    <cfquery name = "qdeletecats" datasource="#request.dsn#">
    DELETE FROM blog_categories_map
    WHERE b_id = <cfqueryparam value="#url.b_id#" cfsqltype="cf_sql_integer"> 
    </cfquery>
</cfif>

<cflocation url = "index.cfm?c=blog&a=default&rinit=1">